package springbook.learningtest.jdk;

import java.lang.reflect.Proxy;

import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

public class HelloUppercaseTest {
		
	@Test
	public void simpleProxy(){
		Hello proxiedHello = new HelloUppercase(new HelloTarget());
		assertThat(proxiedHello.SayHello("Toby"), is("HELLO TOBY"));
		assertThat(proxiedHello.SayHi("Toby"), is("HI TOBY"));
		assertThat(proxiedHello.SayThankYou("Toby"), is("THANK YOU TOBY"));
	}
	
	
	@Test
	public void simpleProxy2(){
		Hello proxiedHello = (Hello) Proxy.newProxyInstance(getClass().getClassLoader(), 
				new Class[]{Hello.class}, new UppercaseHandler(new HelloTarget()));
		assertThat(proxiedHello.SayHello("Toby"), is("HELLO TOBY"));
		assertThat(proxiedHello.SayHi("Toby"), is("HI TOBY"));
		assertThat(proxiedHello.SayThankYou("Toby"), is("THANK YOU TOBY"));
	}
	
	
}
